#ifndef TEMPERATURE_SENSOR_H
#define TEMPERATURE_SENSOR_H

#include "My_Delay.h"
#include "global_resources.h"

#define  TemperatureSensor_PORT         GPIOA
#define  TemperatureSensor_Pin          GPIO_Pin_6
#define  RCC_PERIPH                     RCC_APB2Periph_GPIOA

class TemperatureSensor {
public:
    TemperatureSensor();
    ~TemperatureSensor() = default;

    bool Initialize();
    float GetTemperature();

private:

    void ConfigureInput();
    void ConfigureOutput();
    void ResetPulse();
    bool CheckPresence();
    uint8_t ReadBit();
    uint8_t ReadByte();
    void WriteByte(uint8_t data);
    void StartConversion();

    static constexpr uint8_t CMD_SKIP_ROM = 0xCC;
    static constexpr uint8_t CMD_START_CONV = 0x44;
    static constexpr uint8_t CMD_READ_DATA = 0xBE;
};

#endif
